﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" Inherits="AgentList" Codebehind="AgentList.aspx.cs" %>

<%@ Register TagPrefix="avg" Namespace="Avg.Controls" Assembly="SmartPager" %>
<asp:Content ID="Content2" ContentPlaceHolderID="content" runat="server">
    <div style="margin: 5px">
        <table id="condition">
            <tr>
                <td>
                    <h1 style="text-indent: 10px">
                        Search Agent</h1>
                </td>
            </tr>
            <tr>
                <td>
                    <div class="label">
                        Agent#:</div>
                    <div class="field">
                        <asp:TextBox ID="txtGuestID" runat="server"></asp:TextBox></div>
                </td>
                <td>
                    <div class="label">
                        Name:</div>
                    <div class="field">
                        <asp:TextBox ID="txtGuestName" runat="server"></asp:TextBox></div>
                </td>
                <td>
                    <div class="label">
                        Email:</div>
                    <div class="field">
                        <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox></div>
                </td>
            </tr>
            <tr>
                <td>
                    <div class="label">
                        Address line 1:</div>
                    <div class="field">
                        <asp:TextBox ID="txtAddressLine1" runat="server"></asp:TextBox></div>
                </td>
                <td>
                    <div class="label">
                        Address line 2:</div>
                    <div class="field">
                        <asp:TextBox ID="txtAddressLine2" runat="server"></asp:TextBox></div>
                </td>
                <td>
                    <div class="label">
                        Tel.:</div>
                    <div class="field">
                        <asp:TextBox ID="txtTel" runat="server"></asp:TextBox></div>
                </td>
            </tr>
            <tr>
                <td>
                    <div class="label">
                        Fax:</div>
                    <div class="field">
                        <asp:TextBox ID="txtFax" runat="server"></asp:TextBox></div>
                </td>
                <td>
                    <asp:LinkButton ID="btnFind" runat="server" ToolTip="Search Button" OnClick="btnFind_Click"
                        CssClass="button">
                    <span>Search</span></asp:LinkButton>
                </td>
            </tr>
        </table>
        <div>
            <asp:GridView ID="grv" runat="server" CssClass="grid" AllowSorting="true" AutoGenerateColumns="false"
                DataKeyField="AgentId">
                <Columns>
                    <asp:TemplateField HeaderText="" SortExpression="Name" HeaderStyle-Width="20" HeaderStyle-HorizontalAlign="Center">
                        <ItemTemplate>
                            <%#Container.DataItemIndex+1 %>
                        </ItemTemplate>
                        <HeaderStyle HorizontalAlign="Center" Height="20px"></HeaderStyle>
                        <ItemStyle HorizontalAlign="Center" Height="20px" />
                    </asp:TemplateField>
                    <asp:BoundField HeaderText="Agent#" DataField="GuestID"></asp:BoundField>
                    <asp:BoundField HeaderText="First name" DataField="FirstName"></asp:BoundField>
                    <asp:BoundField HeaderText="Last name" DataField="LastName"></asp:BoundField>
                    <asp:BoundField HeaderText="Address 1" DataField="AddressLine1"></asp:BoundField>
                    <asp:BoundField HeaderText="Address 2" DataField="AddressLine2"></asp:BoundField>
                    <asp:BoundField HeaderText="Tel." DataField="Tel"></asp:BoundField>
                    <asp:BoundField HeaderText="Fax" DataField="Fax"></asp:BoundField>
                    <asp:BoundField HeaderText="Email" DataField="Email"></asp:BoundField>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            <a href="/Pages/Agents/AgentItem.aspx" id="btnNew">Add</a>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <a href="/Pages/Agents/AgentItem.aspx?AgentId=<%#Eval("GuestID") %>" class="btnEdit">
                                Edit</a> |&nbsp;<a agentid="<%#Eval("GuestID") %>" class="btnDelete">Delete</a>
                        </ItemTemplate>
                        <HeaderStyle Width="70"></HeaderStyle>
                    </asp:TemplateField>
                </Columns>
                <HeaderStyle CssClass="gridheader" />
                <RowStyle CssClass="gridrow" />
                <AlternatingRowStyle CssClass="evenRow" />
            </asp:GridView>
            <avg:SmartPager ID="smartPager" runat="server" Visible="false" NavigatePreviousText="« Previous"
                NavigateNextText="Next »">
            </avg:SmartPager>
        </div>
    </div>

    <script type="text/javascript">
        $(document).ready(function () {
            $('#btnNew').button();

            $('.btnDelete').click(function () {
                var result = confirm("Are you sure you want to delete this record?");
                if (result) {

                    var guestID = $(this).attr("agentid");

                    var params = "{ AgentId:'" + guestID + "'}";
                    $.ajax({
                        type: "POST",
                        url: "/Update.asmx/DeleteAgent",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        data: params,
                        success: function (data) {
                            if (data.d) {
                                // Select provider
                                aTag.parents("tr:first").remove();
                                return false;
                            }
                            else {
                                alert("Delete failed.");
                            }
                        },
                        error: function () {
                            alert("error");
                            return false;
                        }
                    });
                }
            });
        });
    </script>

</asp:Content>
